package com.yixing.tech.wms.controller;

import com.yixing.tech.common.base.BaseControl;
import com.yixing.tech.common.base.BusinessException;
import com.yixing.tech.common.base.Rs;
import com.yixing.tech.common.entity.ErpInventoryResult;
import com.yixing.tech.wms.entity.Material;
import com.yixing.tech.wms.service.ErpReportService;
import com.yixing.tech.wms.service.ErpSyncService;
import com.yixing.tech.wms.service.InventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 对接 erp
 *
 * @author yixing tech
 * @since 1.0.0
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/open/erp")
public class ErpController extends BaseControl {

    @Autowired
    private ErpSyncService erpSyncService;
    @Autowired
    private ErpReportService erpReportService;
    @Autowired
    private InventoryService inventoryService;

    /**
     * 测试
     */
    @GetMapping("/test/createPurInStock")
    public Rs<Object> createPurInStock() throws BusinessException {
        return Rs.ok(erpReportService.createPurInStock());
    }


//    /**
//     * 仓库同步
//     */
//    @PostMapping("/sync/warehouse")
//    public Rs<Object> syncWarehouse(@Valid @RequestBody ErpWareHouse erpWareHouse) throws BusinessException {
//        return Rs.ok(erpSyncService.syncWarehouse(erpWareHouse));
//    }

    /**
     * 物料同步
     */
    @PostMapping("/sync/material")
    public Rs<Object> syncMaterial(@Valid @RequestBody Material material) throws BusinessException {
        return Rs.ok(erpSyncService.syncMaterial(material));
    }

    /**
     * 盘盈申请单审核结果
     */
    @PostMapping("/inventory/gain")
    public Rs<Object> erpInventoryGain(@Valid @RequestBody ErpInventoryResult result) throws BusinessException {
        return Rs.ok(inventoryService.erpInventoryGain(result));
    }

    /**
     * 盘亏申请单审核结果
     */
    @PostMapping("/inventory/loss")
    public Rs<Object> erpInventoryLoss(@Valid @RequestBody ErpInventoryResult result) throws BusinessException {
        return Rs.ok(inventoryService.erpInventoryLoss(result));
    }

}
